package com.jason.quectel.activities;

import android.os.Bundle;
import android.view.View;

import com.jason.quectel.R;
import com.jason.quectel.fragment.OneFragment;
import com.jason.quectel.fragment.ThreeFragment;
import com.jason.quectel.fragment.TwoFragment;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class FragmentTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_test);
        switchFragment(new OneFragment());
    }

    private void switchFragment(Fragment fragment) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.fragment_container, fragment).commitAllowingStateLoss();
    }

    public void clickOne(View view) {
        switchFragment(new OneFragment());
    }

    public void clickTwo(View view) {
        switchFragment(new TwoFragment());
    }

    public void clickThree(View view) {
        switchFragment(new ThreeFragment());
    }
}